<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>tests/src/vfs/extfs/helpers-list/test_all</title>
<meta name='robots' content='noindex,nofollow' />
<meta name='generator' content='GLOBAL-6.5.7' />
<meta http-equiv='Content-Style-Type' content='text/css' />
<link rel='stylesheet' type='text/css' href='../style.css' />
</head>
<body>
<!-- beginning of fixed guide -->
<div id='guide'><ul>
<li><a href='#TOP'><img class='icon' src='../icons/first.png' alt='[^]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/last.png' alt='[v]' /></a></li>
<li><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a></li>
<li><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a></li>
<li><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a></li>
<li><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a></li>
<li class='standout'><span><a href='../files/tests.html'>tests</a>/<a href='../files/tests--src.html'>src</a>/<a href='../files/tests--src--vfs.html'>vfs</a>/<a href='../files/tests--src--vfs--extfs.html'>extfs</a>/<a href='../files/tests--src--vfs--extfs--helpers-list.html'>helpers-list</a>/test_all</span></li>
</ul></div>
<!-- end of fixed guide -->
<a id='TOP' name='TOP'></a><h2 class='header'><a href='../mains.html'>root</a>/<a href='../files/tests.html'>tests</a>/<a href='../files/tests--src.html'>src</a>/<a href='../files/tests--src--vfs.html'>vfs</a>/<a href='../files/tests--src--vfs--extfs.html'>extfs</a>/<a href='../files/tests--src--vfs--extfs--helpers-list.html'>helpers-list</a>/test_all</h2>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><img class='icon' src='../icons/n_top.png' alt='[top]' /><a href='#BOTTOM'><img class='icon' src='../icons/bottom.png' alt='[bottom]' /></a><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+1 tests/src/vfs/extfs/helpers-list/test_all'  /> */</em>
<hr />
<pre>
<a id='L1' name='L1'></a>#!/bin/sh
<a id='L2' name='L2'></a> 
<a id='L3' name='L3'></a># A tester for extfs helpers.
<a id='L4' name='L4'></a>#
<a id='L5' name='L5'></a># Copyright (C) 2016-2017
<a id='L6' name='L6'></a># The Free Software Foundation, Inc.
<a id='L7' name='L7'></a>#
<a id='L8' name='L8'></a># This file is part of the Midnight Commander.
<a id='L9' name='L9'></a>#
<a id='L10' name='L10'></a># The Midnight Commander is free software: you can redistribute it
<a id='L11' name='L11'></a># and/or modify it under the terms of the GNU General Public License as
<a id='L12' name='L12'></a># published by the Free Software Foundation, either version 3 of the License,
<a id='L13' name='L13'></a># or (at your option) any later version.
<a id='L14' name='L14'></a>#
<a id='L15' name='L15'></a># The Midnight Commander is distributed in the hope that it will be useful,
<a id='L16' name='L16'></a># but WITHOUT ANY WARRANTY; without even the implied warranty of
<a id='L17' name='L17'></a># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
<a id='L18' name='L18'></a># GNU General Public License for more details.
<a id='L19' name='L19'></a>#
<a id='L20' name='L20'></a># You should have received a copy of the GNU General Public License
<a id='L21' name='L21'></a># along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
<a id='L22' name='L22'></a> 
<a id='L23' name='L23'></a>help() {
<a id='L24' name='L24'></a>  cat &lt;&lt; EOS
<a id='L25' name='L25'></a> 
<a id='L26' name='L26'></a>NAME
<a id='L27' name='L27'></a> 
<a id='L28' name='L28'></a>$(basename "$0") - Tests the 'list' command of extfs helpers.
<a id='L29' name='L29'></a> 
<a id='L30' name='L30'></a>SYNOPSIS
<a id='L31' name='L31'></a> 
<a id='L32' name='L32'></a>  $(basename "$0") \\
<a id='L33' name='L33'></a>     --data-dir /path/to/where/data/files/are/stored \\
<a id='L34' name='L34'></a>     --helpers-dir /path/to/where/helpers/are/stored \\
<a id='L35' name='L35'></a>     --data-build-dir /path/to/where/config.sh/is/stored
<a id='L36' name='L36'></a> 
<a id='L37' name='L37'></a>(But you're more likely to invoke this program with the 'run' script
<a id='L38' name='L38'></a>created by 'make check'; or by 'make check' itself.)
<a id='L39' name='L39'></a> 
<a id='L40' name='L40'></a>DESCRIPTION
<a id='L41' name='L41'></a> 
<a id='L42' name='L42'></a>This program tests extfs helpers by feeding them input and comparing
<a id='L43' name='L43'></a>their output to the expected output.
<a id='L44' name='L44'></a> 
<a id='L45' name='L45'></a>See README for full details.
<a id='L46' name='L46'></a> 
<a id='L47' name='L47'></a>You need to tell this program primarily two things: where the helpers are
<a id='L48' name='L48'></a>stored, and where the "data files" are stored. The data files are *.input
<a id='L49' name='L49'></a>files that are fed to the helpers and *.output files that are the correct
<a id='L50' name='L50'></a>output expected from these helpers.
<a id='L51' name='L51'></a> 
<a id='L52' name='L52'></a>You also need to tell this program where the build flavor of the "data
<a id='L53' name='L53'></a>files" is stored. Most notably this is where the 'config.sh' file is
<a id='L54' name='L54'></a>created during build time. You do this with '--data-build-dir'.
<a id='L55' name='L55'></a> 
<a id='L56' name='L56'></a>EOS
<a id='L57' name='L57'></a>}
<a id='L58' name='L58'></a> 
<a id='L59' name='L59'></a>#"'
<a id='L60' name='L60'></a> 
<a id='L61' name='L61'></a>#
<a id='L62' name='L62'></a># Some helpers use the 'sort' utility. The "expected output" files we
<a id='L63' name='L63'></a># provide must be generated in the same locale these helpers are to be run
<a id='L64' name='L64'></a># by the tester or else 'sort' will produce a different output than ours,
<a id='L65' name='L65'></a># failing the tests.
<a id='L66' name='L66'></a>#
<a id='L67' name='L67'></a># We settle on the C locale.
<a id='L68' name='L68'></a>#
<a id='L69' name='L69'></a>LC_ALL=C
<a id='L70' name='L70'></a>export LC_ALL
<a id='L71' name='L71'></a> 
<a id='L72' name='L72'></a>############################ Global variables ##############################
<a id='L73' name='L73'></a> 
<a id='L74' name='L74'></a># The directories used.
<a id='L75' name='L75'></a>data_dir=
<a id='L76' name='L76'></a>data_build_dir=
<a id='L77' name='L77'></a>helpers_dir1=
<a id='L78' name='L78'></a>helpers_dir2=
<a id='L79' name='L79'></a> 
<a id='L80' name='L80'></a>opt_create_output=no        # "yes" if '--create-output' provided.
<a id='L81' name='L81'></a>opt_run_mcdiff_on_error=no  # "yes" if '--mcdiff' provided.
<a id='L82' name='L82'></a> 
<a id='L83' name='L83'></a>############################ Coding guidance ###############################
<a id='L84' name='L84'></a> 
<a id='L85' name='L85'></a>#
<a id='L86' name='L86'></a># Portability notes:
<a id='L87' name='L87'></a>#
<a id='L88' name='L88'></a># - We do `local var="$whatever"` instead of `local var=$whatever` for
<a id='L89' name='L89'></a>#   compatibility with Dash. See http://unix.stackexchange.com/questions/97560.
<a id='L90' name='L90'></a>#
<a id='L91' name='L91'></a># - The 'local' keyword used in this file isn't mandatory. Feel free to
<a id='L92' name='L92'></a>#   remove it if it isn't supported by your archaic shell.
<a id='L93' name='L93'></a>#
<a id='L94' name='L94'></a> 
<a id='L95' name='L95'></a>############################ Utility functions #############################
<a id='L96' name='L96'></a> 
<a id='L97' name='L97'></a>#
<a id='L98' name='L98'></a># Does $1 contain $2?
<a id='L99' name='L99'></a>#
<a id='L100' name='L100'></a># Accepts basic regex.
<a id='L101' name='L101'></a>#
<a id='L102' name='L102'></a>has_string() {
<a id='L103' name='L103'></a>  local haystack="$1"  # quotes needed for Dash, as may contain spaces (see notes above).
<a id='L104' name='L104'></a>  local needle="$2"
<a id='L105' name='L105'></a>  echo "$haystack" | grep "$needle" &gt; /dev/null
<a id='L106' name='L106'></a>}
<a id='L107' name='L107'></a> 
<a id='L108' name='L108'></a>#
<a id='L109' name='L109'></a># Given "/path/to/basename.and.some.ext", returns "basename"
<a id='L110' name='L110'></a>#
<a id='L111' name='L111'></a>basename_sans_extensions() {
<a id='L112' name='L112'></a>  local base="$(basename "$1")"
<a id='L113' name='L113'></a>  echo "${base%%.*}"
<a id='L114' name='L114'></a>}
<a id='L115' name='L115'></a> 
<a id='L116' name='L116'></a>#
<a id='L117' name='L117'></a># Does an executable exist?
<a id='L118' name='L118'></a>#
<a id='L119' name='L119'></a>has_prog() {
<a id='L120' name='L120'></a>  # see http://stackoverflow.com/questions/592620
<a id='L121' name='L121'></a>  command -v "$1" &gt;/dev/null 2&gt;&amp;1
<a id='L122' name='L122'></a>}
<a id='L123' name='L123'></a> 
<a id='L124' name='L124'></a>#
<a id='L125' name='L125'></a># Are we running interactively? Or is our output redirected to a file/pipe?
<a id='L126' name='L126'></a>#
<a id='L127' name='L127'></a>is_interactive() {
<a id='L128' name='L128'></a>  [ -t 1 ]
<a id='L129' name='L129'></a>}
<a id='L130' name='L130'></a> 
<a id='L131' name='L131'></a>#
<a id='L132' name='L132'></a># Can we use colors?
<a id='L133' name='L133'></a>#
<a id='L134' name='L134'></a>has_colors() {
<a id='L135' name='L135'></a>  is_interactive &amp;&amp; has_string "$TERM" 'linux\|xterm\|screen\|tmux\|putty'
<a id='L136' name='L136'></a>}
<a id='L137' name='L137'></a> 
<a id='L138' name='L138'></a>init_colors() {
<a id='L139' name='L139'></a>  if has_colors; then
<a id='L140' name='L140'></a>    local esc="$(printf '\033')"  # for portability
<a id='L141' name='L141'></a>    C_bold="$esc[1m"
<a id='L142' name='L142'></a>    C_green="$esc[1;32m"
<a id='L143' name='L143'></a>    C_red="$esc[1;31m"
<a id='L144' name='L144'></a>    C_magenta="$esc[1;35m"
<a id='L145' name='L145'></a>    C_norm="$esc[0m"
<a id='L146' name='L146'></a>  fi
<a id='L147' name='L147'></a>}
<a id='L148' name='L148'></a> 
<a id='L149' name='L149'></a>#
<a id='L150' name='L150'></a># A few colorful alternatives to 'echo'.
<a id='L151' name='L151'></a>#
<a id='L152' name='L152'></a>header()  { echo $C_bold"$@"$C_norm; }
<a id='L153' name='L153'></a>err()     { echo $C_red"$@"$C_norm; }
<a id='L154' name='L154'></a>notice()  { echo $C_magenta"$@"$C_norm; }
<a id='L155' name='L155'></a>success() { echo $C_green"$@"$C_norm; }
<a id='L156' name='L156'></a> 
<a id='L157' name='L157'></a>die() {
<a id='L158' name='L158'></a>  err "Error: $@"
<a id='L159' name='L159'></a>  exit 1
<a id='L160' name='L160'></a>}
<a id='L161' name='L161'></a> 
<a id='L162' name='L162'></a>assert_dir_exists() {
<a id='L163' name='L163'></a>  [ -d "$1" ] || die "The directory '$1' doesn't exist, or is not a directory."
<a id='L164' name='L164'></a>}
<a id='L165' name='L165'></a> 
<a id='L166' name='L166'></a>#
<a id='L167' name='L167'></a># Creates a temporary file.
<a id='L168' name='L168'></a>#
<a id='L169' name='L169'></a>temp_file() {
<a id='L170' name='L170'></a>  local template="$1"
<a id='L171' name='L171'></a>  # BSD's doesn't support -t.
<a id='L172' name='L172'></a>  mktemp "${TMPDIR:-/tmp}/$template"
<a id='L173' name='L173'></a>}
<a id='L174' name='L174'></a> 
<a id='L175' name='L175'></a>################################ Main code #################################
<a id='L176' name='L176'></a> 
<a id='L177' name='L177'></a>#
<a id='L178' name='L178'></a># Prints out the command to run a helper, if it can find it.
<a id='L179' name='L179'></a>#
<a id='L180' name='L180'></a># For example,
<a id='L181' name='L181'></a>#
<a id='L182' name='L182'></a>#    find_helper uzip /path/to/helpers/dir
<a id='L183' name='L183'></a>#
<a id='L184' name='L184'></a># prints:
<a id='L185' name='L185'></a>#
<a id='L186' name='L186'></a>#    /usr/bin/perl -w /path/to/helpers/dir/uzip
<a id='L187' name='L187'></a>#
<a id='L188' name='L188'></a># Since helpers in the build tree don't yet have executable bit set, we
<a id='L189' name='L189'></a># need to extract the shebang line.
<a id='L190' name='L190'></a>#
<a id='L191' name='L191'></a>find_helper() {
<a id='L192' name='L192'></a>  local helper_name="$1"
<a id='L193' name='L193'></a>  local dir="$2"
<a id='L194' name='L194'></a> 
<a id='L195' name='L195'></a>  local try="$dir/$helper_name"
<a id='L196' name='L196'></a>  if [ -f "$try" ]; then
<a id='L197' name='L197'></a>    helper_CMD="$(head -1 $try | cut -c 3-) $try"  # reason #1 we don't allow spaces in pathnames.
<a id='L198' name='L198'></a>    true
<a id='L199' name='L199'></a>  else
<a id='L200' name='L200'></a>    false
<a id='L201' name='L201'></a>  fi
<a id='L202' name='L202'></a>}
<a id='L203' name='L203'></a> 
<a id='L204' name='L204'></a>#
<a id='L205' name='L205'></a># Returns the path of 'config.sh'.
<a id='L206' name='L206'></a>#
<a id='L207' name='L207'></a>path_of_config_sh() {
<a id='L208' name='L208'></a>  echo "$data_build_dir/config.sh"
<a id='L209' name='L209'></a>}
<a id='L210' name='L210'></a> 
<a id='L211' name='L211'></a>#
<a id='L212' name='L212'></a># Export variables to be used by tests.
<a id='L213' name='L213'></a>#
<a id='L214' name='L214'></a># See README for their documentation.
<a id='L215' name='L215'></a>#
<a id='L216' name='L216'></a>export_useful_variables() {
<a id='L217' name='L217'></a>  local input="$1"
<a id='L218' name='L218'></a> 
<a id='L219' name='L219'></a>  # Frequently used variables:
<a id='L220' name='L220'></a>  MC_TEST_EXTFS_LIST_CMD="mc_xcat $input"  # reason #2 we don't allow spaces in pathnames.
<a id='L221' name='L221'></a>  export MC_TEST_EXTFS_LIST_CMD
<a id='L222' name='L222'></a> 
<a id='L223' name='L223'></a>  # Infrequently used variables:
<a id='L224' name='L224'></a>  MC_TEST_EXTFS_INPUT=$input
<a id='L225' name='L225'></a>  export MC_TEST_EXTFS_INPUT
<a id='L226' name='L226'></a>  MC_TEST_EXTFS_DATA_DIR=$data_dir
<a id='L227' name='L227'></a>  export MC_TEST_EXTFS_DATA_DIR
<a id='L228' name='L228'></a>  MC_TEST_EXTFS_DATA_BUILD_DIR=$data_build_dir
<a id='L229' name='L229'></a>  export MC_TEST_EXTFS_DATA_BUILD_DIR
<a id='L230' name='L230'></a>  MC_TEST_EXTFS_CONFIG_SH=$(path_of_config_sh)
<a id='L231' name='L231'></a>  export MC_TEST_EXTFS_CONFIG_SH
<a id='L232' name='L232'></a>}
<a id='L233' name='L233'></a> 
<a id='L234' name='L234'></a>#
<a id='L235' name='L235'></a># The crux of this program.
<a id='L236' name='L236'></a>#
<a id='L237' name='L237'></a>run() {
<a id='L238' name='L238'></a> 
<a id='L239' name='L239'></a>  local error_count=0
<a id='L240' name='L240'></a>  local pass_count=0
<a id='L241' name='L241'></a> 
<a id='L242' name='L242'></a>  for input in "$data_dir"/*.input; do
<a id='L243' name='L243'></a> 
<a id='L244' name='L244'></a>    has_string "$input" '\*' &amp;&amp; break  # we can't use 'shopt -s nullglob' as it's bash-specific.
<a id='L245' name='L245'></a> 
<a id='L246' name='L246'></a>    header "Testing $input"
<a id='L247' name='L247'></a> 
<a id='L248' name='L248'></a>    has_string "$input" " " &amp;&amp; die "Error: filename contains spaces."
<a id='L249' name='L249'></a> 
<a id='L250' name='L250'></a>    #
<a id='L251' name='L251'></a>    # Set up variables:
<a id='L252' name='L252'></a>    #
<a id='L253' name='L253'></a> 
<a id='L254' name='L254'></a>    local helper_name="$(basename_sans_extensions "$input")"
<a id='L255' name='L255'></a>    local expected_parsed_output="${input%.input}.output"
<a id='L256' name='L256'></a>    local env_vars_file="${input%.input}.env_vars"
<a id='L257' name='L257'></a>    local args_file="${input%.input}.args"
<a id='L258' name='L258'></a> 
<a id='L259' name='L259'></a>    local do_create_output=no
<a id='L260' name='L260'></a> 
<a id='L261' name='L261'></a>    if [ ! -f "$expected_parsed_output" ]; then
<a id='L262' name='L262'></a>      # Corresponding *.output file doesn't exist. We either create it, later, or exit with error.
<a id='L263' name='L263'></a>      if [ $opt_create_output = "yes" ]; then
<a id='L264' name='L264'></a>        do_create_output=yes
<a id='L265' name='L265'></a>      else
<a id='L266' name='L266'></a>        err
<a id='L267' name='L267'></a>        err "Missing file: '$expected_parsed_output'."
<a id='L268' name='L268'></a>        err "You have to create an '.output' file for each '.input' one."
<a id='L269' name='L269'></a>        err
<a id='L270' name='L270'></a>        notice "Tip: invoke this program with '--create-output' to"
<a id='L271' name='L271'></a>        notice "automatically create missing '.output' files."
<a id='L272' name='L272'></a>        notice
<a id='L273' name='L273'></a>        exit 1
<a id='L274' name='L274'></a>      fi
<a id='L275' name='L275'></a>    fi
<a id='L276' name='L276'></a> 
<a id='L277' name='L277'></a>    find_helper "$helper_name" "$helpers_dir1" ||
<a id='L278' name='L278'></a>      find_helper "$helper_name" "$helpers_dir2" ||
<a id='L279' name='L279'></a>        die "I can't find helper '$helper_name' in either $helpers_dir1 or $helpers_dir2"
<a id='L280' name='L280'></a> 
<a id='L281' name='L281'></a>    local extra_parser_args=""
<a id='L282' name='L282'></a>    [ -f "$args_file" ] &amp;&amp; extra_parser_args="$(cat "$args_file")"
<a id='L283' name='L283'></a> 
<a id='L284' name='L284'></a>    local actual_output="$(temp_file $helper_name.actual-output.XXXXXXXX)"
<a id='L285' name='L285'></a>    local actual_parsed_output="$(temp_file $helper_name.actual-parsed-output.XXXXXXXX)"
<a id='L286' name='L286'></a> 
<a id='L287' name='L287'></a>    #
<a id='L288' name='L288'></a>    # Variables are all set. Now do the actual stuff:
<a id='L289' name='L289'></a>    #
<a id='L290' name='L290'></a> 
<a id='L291' name='L291'></a>    (
<a id='L292' name='L292'></a>    export_useful_variables "$input"
<a id='L293' name='L293'></a>    if [ -f "$env_vars_file" ]; then
<a id='L294' name='L294'></a>      set -a  # "allexport: Export all variables assigned to."
<a id='L295' name='L295'></a>      . "$env_vars_file"
<a id='L296' name='L296'></a>      set +a
<a id='L297' name='L297'></a>    fi
<a id='L298' name='L298'></a>    $helper_CMD list /dev/null &gt; "$actual_output"
<a id='L299' name='L299'></a>    )
<a id='L300' name='L300'></a> 
<a id='L301' name='L301'></a>    error_count=$((error_count + 1))  # we'll decrement it later.
<a id='L302' name='L302'></a> 
<a id='L303' name='L303'></a>    if [ ! -s "$actual_output" ]; then
<a id='L304' name='L304'></a>      err
<a id='L305' name='L305'></a>      err "The helper '$helper_name' produced no output for this input. Something is wrong."
<a id='L306' name='L306'></a>      err
<a id='L307' name='L307'></a>      err "Make sure this helper supports testability: that it uses \$MC_TEST_EXTFS_LIST_CMD."
<a id='L308' name='L308'></a>      err
<a id='L309' name='L309'></a>      err "You may try running the helper yourself with:"
<a id='L310' name='L310'></a>      err
<a id='L311' name='L311'></a>      err "  \$ MC_TEST_EXTFS_LIST_CMD=\"mc_xcat $input\" \\"
<a id='L312' name='L312'></a>      err "      $helper_CMD list /dev/null"
<a id='L313' name='L313'></a>      err
<a id='L314' name='L314'></a>      continue
<a id='L315' name='L315'></a>    fi
<a id='L316' name='L316'></a> 
<a id='L317' name='L317'></a>    # '--symbolic-ids': uid/gid aren't portable between computers,
<a id='L318' name='L318'></a>    # of course, so we always represent them symbolically when possible.
<a id='L319' name='L319'></a>    if ! mc_parse_ls_l --symbolic-ids $extra_parser_args "$actual_output" &gt; "$actual_parsed_output"; then
<a id='L320' name='L320'></a>      err
<a id='L321' name='L321'></a>      err "ERROR: Parsing of the output of the helper '$helper_name' has failed."
<a id='L322' name='L322'></a>      err "This means that $helper_name has produced output that MC won't be able to parse."
<a id='L323' name='L323'></a>      err "Run the parsing command yourself ('mc_parse_ls_l $extra_parser_args $actual_output')"
<a id='L324' name='L324'></a>      err "to figure out the problem."
<a id='L325' name='L325'></a>      err
<a id='L326' name='L326'></a>      continue
<a id='L327' name='L327'></a>    fi
<a id='L328' name='L328'></a> 
<a id='L329' name='L329'></a>    if [ $do_create_output = "yes" ]; then
<a id='L330' name='L330'></a>      # We arrive here if we were invoked with '--create-output' and
<a id='L331' name='L331'></a>      # the .output file doesn't exist. We create it and move to the next iteration.
<a id='L332' name='L332'></a>      cp "$actual_parsed_output" "$expected_parsed_output"
<a id='L333' name='L333'></a>      notice "The output file has been created in $expected_parsed_output"
<a id='L334' name='L334'></a>      continue
<a id='L335' name='L335'></a>    fi
<a id='L336' name='L336'></a> 
<a id='L337' name='L337'></a>    if ! cmp "$expected_parsed_output" "$actual_parsed_output"; then
<a id='L338' name='L338'></a>      err
<a id='L339' name='L339'></a>      err "ERROR: $helper_name has produced output that's different than the expected output."
<a id='L340' name='L340'></a>      err
<a id='L341' name='L341'></a>      err "  Expected output (after parsing): $expected_parsed_output"
<a id='L342' name='L342'></a>      err "  Actual output (after parsing): $actual_parsed_output"
<a id='L343' name='L343'></a>      err
<a id='L344' name='L344'></a>      err "This might mean that a bug was introduced into $helper_name. Or that a bug was fixed."
<a id='L345' name='L345'></a>      err "Please compare the files."
<a id='L346' name='L346'></a>      err
<a id='L347' name='L347'></a>      err "If the actual output is the correct one, just copy the latter file"
<a id='L348' name='L348'></a>      err "onto the former (and commit to the git repository)."
<a id='L349' name='L349'></a>      err
<a id='L350' name='L350'></a>      if is_interactive; then
<a id='L351' name='L351'></a>        if [ $opt_run_mcdiff_on_error = "yes" ]; then
<a id='L352' name='L352'></a>          notice "Hit ENTER to launch mcdiff ..."
<a id='L353' name='L353'></a>          read dummy_var  # dash needs this.
<a id='L354' name='L354'></a>          ${MCDIFF:-mcdiff} "$expected_parsed_output" "$actual_parsed_output"
<a id='L355' name='L355'></a>        else
<a id='L356' name='L356'></a>          notice "Tip: invoke this program with '--mcdiff' to automatically launch"
<a id='L357' name='L357'></a>          notice "mcdiff to visually inspect the diff."
<a id='L358' name='L358'></a>          notice
<a id='L359' name='L359'></a>          notice "(Running this program non-interactively (i.e., redirecting the"
<a id='L360' name='L360'></a>          notice "output to a file or pipe) automatically adds diff to the output.)"
<a id='L361' name='L361'></a>          notice
<a id='L362' name='L362'></a>        fi
<a id='L363' name='L363'></a>      else
<a id='L364' name='L364'></a>        err "------------ diff of the expected output vs the actual output: -------------"
<a id='L365' name='L365'></a>        diff -U2 "$expected_parsed_output" "$actual_parsed_output"
<a id='L366' name='L366'></a>        err "------------------------------- end of diff --------------------------------"
<a id='L367' name='L367'></a>      fi
<a id='L368' name='L368'></a>      continue
<a id='L369' name='L369'></a>    fi
<a id='L370' name='L370'></a> 
<a id='L371' name='L371'></a>    rm "$actual_output" "$actual_parsed_output"
<a id='L372' name='L372'></a> 
<a id='L373' name='L373'></a>    error_count=$((error_count - 1))  # cancel the earlier "+1".
<a id='L374' name='L374'></a>    pass_count=$((pass_count + 1))
<a id='L375' name='L375'></a> 
<a id='L376' name='L376'></a>    success "PASSED."
<a id='L377' name='L377'></a> 
<a id='L378' name='L378'></a>  done
<a id='L379' name='L379'></a> 
<a id='L380' name='L380'></a>  [ $pass_count = "0" -a $error_count = "0" ] &amp;&amp; notice "Note: The data directory contains no *.input files."
<a id='L381' name='L381'></a> 
<a id='L382' name='L382'></a>  [ $error_count = "0" ]  # exit status of function.
<a id='L383' name='L383'></a>}
<a id='L384' name='L384'></a> 
<a id='L385' name='L385'></a>parse_command_line_arguments() {
<a id='L386' name='L386'></a>  # We want --long-options, so we don't use 'getopts'.
<a id='L387' name='L387'></a>  while [ -n "$1" ]; do
<a id='L388' name='L388'></a>    case "$1" in
<a id='L389' name='L389'></a>      --data-dir)
<a id='L390' name='L390'></a>        data_dir=$2
<a id='L391' name='L391'></a>        shift 2
<a id='L392' name='L392'></a>        ;;
<a id='L393' name='L393'></a>      --data-build-dir)
<a id='L394' name='L394'></a>        data_build_dir=$2
<a id='L395' name='L395'></a>        shift 2
<a id='L396' name='L396'></a>        ;;
<a id='L397' name='L397'></a>      --helpers-dir)
<a id='L398' name='L398'></a>        if [ -z "$helpers_dir1" ]; then
<a id='L399' name='L399'></a>          helpers_dir1=$2
<a id='L400' name='L400'></a>        else
<a id='L401' name='L401'></a>          helpers_dir2=$2
<a id='L402' name='L402'></a>        fi
<a id='L403' name='L403'></a>        shift 2
<a id='L404' name='L404'></a>        ;;
<a id='L405' name='L405'></a>      --create-output)
<a id='L406' name='L406'></a>        opt_create_output=yes
<a id='L407' name='L407'></a>        shift
<a id='L408' name='L408'></a>        ;;
<a id='L409' name='L409'></a>      --mcdiff)
<a id='L410' name='L410'></a>        opt_run_mcdiff_on_error=yes
<a id='L411' name='L411'></a>        shift
<a id='L412' name='L412'></a>        ;;
<a id='L413' name='L413'></a>      --help|-h)
<a id='L414' name='L414'></a>        help
<a id='L415' name='L415'></a>        exit
<a id='L416' name='L416'></a>        ;;
<a id='L417' name='L417'></a>      *)
<a id='L418' name='L418'></a>        die "Unknown command-line option $1"
<a id='L419' name='L419'></a>        ;;
<a id='L420' name='L420'></a>    esac
<a id='L421' name='L421'></a>  done
<a id='L422' name='L422'></a>}
<a id='L423' name='L423'></a> 
<a id='L424' name='L424'></a>#
<a id='L425' name='L425'></a># Check that everything is set up correctly.
<a id='L426' name='L426'></a>#
<a id='L427' name='L427'></a>verify_setup() {
<a id='L428' name='L428'></a>  [ -n "$data_dir" ] || die "You didn't specify the data dir (--data-dir). Run me with --help for info."
<a id='L429' name='L429'></a>  [ -n "$data_build_dir" ] || die "You didn't specify the data build dir (--data-build-dir). Run me with --help for info."
<a id='L430' name='L430'></a>  [ -n "$helpers_dir1" ] || die "You didn't specify the helpers dir (--helpers-dir). Run me with --help for info."
<a id='L431' name='L431'></a>  [ -z "$helpers_dir2" ] &amp;&amp; helpers_dir2=$helpers_dir1  # we're being lazy.
<a id='L432' name='L432'></a> 
<a id='L433' name='L433'></a>  local dir
<a id='L434' name='L434'></a>  for dir in "$data_dir" "$data_build_dir" "$helpers_dir1" "$helpers_dir2"; do
<a id='L435' name='L435'></a>    assert_dir_exists "$dir"
<a id='L436' name='L436'></a>    has_string "$dir" " " &amp;&amp; die "$dir: Sorry, spaces aren't allowed in pathnames."  # search "reason", twice, above.
<a id='L437' name='L437'></a>  done
<a id='L438' name='L438'></a> 
<a id='L439' name='L439'></a>  [ -e "$(path_of_config_sh)" ] || die "Missing file $(path_of_config_sh). You probably have a mistake in the '--data-build-dir' path."
<a id='L440' name='L440'></a> 
<a id='L441' name='L441'></a>  local missing_progs=""
<a id='L442' name='L442'></a>  check_prog() {
<a id='L443' name='L443'></a>    if ! has_prog "$1"; then
<a id='L444' name='L444'></a>      err "I can't see the program '$1'."
<a id='L445' name='L445'></a>      missing_progs="${missing_progs}${missing_progs:+ and }'$1'"
<a id='L446' name='L446'></a>    fi
<a id='L447' name='L447'></a>  }
<a id='L448' name='L448'></a> 
<a id='L449' name='L449'></a>  check_prog "mc_parse_ls_l"
<a id='L450' name='L450'></a>  check_prog "mc_xcat"
<a id='L451' name='L451'></a>  check_prog "mktemp"  # non-POSIX
<a id='L452' name='L452'></a>  [ -z "$missing_progs" ] || die "You need to add to your PATH the directories containing the executables $missing_progs."
<a id='L453' name='L453'></a>}
<a id='L454' name='L454'></a> 
<a id='L455' name='L455'></a>main() {
<a id='L456' name='L456'></a>  init_colors
<a id='L457' name='L457'></a>  parse_command_line_arguments "$@"
<a id='L458' name='L458'></a>  verify_setup
<a id='L459' name='L459'></a>  run  # being the last command executed, its exit status is that of this whole script.
<a id='L460' name='L460'></a>}
<a id='L461' name='L461'></a> 
<a id='L462' name='L462'></a>main "$@"
</pre>
<hr />
<a id='BOTTOM' name='BOTTOM'></a>
<em class='comment'>/* <img class='icon' src='../icons/n_left.png' alt='[previous]' /><img class='icon' src='../icons/n_right.png' alt='[next]' /><img class='icon' src='../icons/n_first.png' alt='[first]' /><img class='icon' src='../icons/n_last.png' alt='[last]' /><a href='#TOP'><img class='icon' src='../icons/top.png' alt='[top]' /></a><img class='icon' src='../icons/n_bottom.png' alt='[bottom]' /><a href='../mains.html'><img class='icon' src='../icons/index.png' alt='[index]' /></a><a href='../help.html'><img class='icon' src='../icons/help.png' alt='[help]' /></a>&nbsp;<input type='text' readonly onfocus='this.select();' value='+462 tests/src/vfs/extfs/helpers-list/test_all'  /> */</em>
</body>
</html>
